home *** CD-ROM | disk | FTP | other *** search
- real p0[], p1[], p2[], p3[];
- real timeArray[]; ** for discrete event Exec testing
- integer con0, con1, con2, con3, out0, out1, out2, out3;
- integer nSteps, cStep, saveNSteps, incoming;
-
- ** This is just the plotter from the Electronics library with a new face
- ** Copyright © 1989-1994 by Imagine That, Inc.
- ** All Rights Reserved.
- ** Extend Plotter Library, Plotter, I/O; Bob Diamond
- ** modified 12/13/91 JSL modified for V2.0
- ** 2/23/93 JSL added incoming for Output only plotters
- ** 10/8/93 JSL changed in0-3 to con0-3 + added report data
- ** 2/1/94 DJK added show plot at end of simulation
- ** 2/23/94 DJK modified error check for n (number of observations between plot points) to < 100000
- ** 4/1/94 DJK modified report and trace
- ** 6/2/94 DJK added openModel message handler
-
- on checkData
- {
- sysGlobal1 = 0.0; ** prevent false reports
- sysGlobal2 = 0.0; ** prevent false debugs
-
- ** Find out if inputs are connected to determine
- ** which are being used as input or output
- ** and save their states for plotting decisions
- ** in simulate message
- con0 = con0in; ** save values for later decisions
- con1 = con1in; ** as integer (faster)
- con2 = con2in; ** They are TRUE if inputs
- con3 = con3in; ** connected to a signal
-
- incoming = con3 + con2 + con1 + con0;
-
- out0 = con0out; ** save values for later decisions
- out1 = con1out; ** as integer (faster)
- out2 = con2out; ** They are TRUE if inputs
- out3 = con3out; ** connected to a signal
-
- if (incoming && !out0)
- {
- makeArray(p0, 0); ** compress arrays
- installArray(0, 0, "", p0, startTime, endTime,
- 0, 0, blackPattern, cyanColor);
- }
- if (incoming && !out1)
- {
- makeArray(p1, 0);
- installArray(0, 1, "", p1, startTime, endTime,
- 0, 0, dkgrayPattern, redColor);
- }
- if (incoming && !out2)
- {
- makeArray(p2, 0);
- installArray(0, 2, "", p2, startTime, endTime,
- 0, 0, grayPattern, greenColor);
- }
- if (incoming && !out3)
- {
- makeArray(p3, 0);
- installArray(0, 3, "", p3, startTime, endTime,
- 0, 0, ltgrayPattern, blackColor);
- }
-
- if (nth && (noValue(n) || n < 2 || n > 100000))
- {
- userError("N must be between 2 and 100000 in Plotter I/O block.");
- abort;
- }
- }
-
- on initsim
- {
- ** First check to make sure Discrete Event Exec is not being used
- if( getPassedArray(sysGlobal0, timeArray) )
- {
- userError("The Plotter I/O does not work with the Discrete Event Exec in block number "+(MyBlockNumber()));
- abort;
- }
-
- ** if no inputs are connected, don't do anything
- ** so that the user can use the saved data for input
- if (not (con0 || con1 || con2 || con3))
- return;
-
- ** set up the local numsteps if using nth point
- if (nth)
- nSteps = numSteps / n + 1;
- else
- nSteps = numSteps;
-
- ** check each input connector. If it is connected
- ** the user is using that signal to plot simulation
- ** results, so resize the array using makeArray.
-
- ** If it isn't connected, compress the signal array
-
- if (con0) ** is input connector TRUE (connected)
- makeArray(p0, nsteps); ** yes, input. Resize array
- else
- makeArray(p0, 0); ** no, compress array
- if (con1) ** is input connector TRUE (connected)
- makeArray(p1, nsteps); ** yes, input. Resize array
- else
- makeArray(p1, 0); ** no, compress array
- if (con2) ** is input connector TRUE (connected)
- makeArray(p2, nsteps); ** yes, input. Resize array
- else
- makeArray(p2, 0); ** no, compress array
- if (con3) ** is input connector TRUE (connected)
- makeArray(p3, nsteps); ** yes, input. Resize array
- else
- makeArray(p3, 0); ** no, compress array
-
- installArray(0, 0, "", p0, startTime, endTime,
- 0, 0, blackPattern, cyanColor);
- installArray(0, 1, "", p1, startTime, endTime,
- 0, 0, dkgrayPattern, redColor);
- installArray(0, 2, "", p2, startTime, endTime,
- 0, 0, grayPattern, greenColor);
- installArray(0, 3, "", p3, startTime, endTime,
- 0, 0, ltgrayPattern, blackColor);
-
- if (nth)
- {
- saveNSteps = numSteps;
- numSteps = nSteps;
- }
-
- retimeAxis(0);
- if (nth)
- numSteps = saveNSteps;
-
- if( showDuring )
- showPlot(0, "Plotter I/O");
- }
-
-
- on simulate
- {
- ** check each saved input connector state
-
- ** if it is TRUE, the input connector was
- ** connected, so plot the new point and also
- ** pass the value to the output in case it is
- ** also connected.
-
- ** if it is FALSE, the input connector wasn't
- ** connected, so get the output value from
- ** the previously stored signal in the plot
- ** and put it in the output connector
-
- if (nth && (currentStep mod n != 1))
- return;
-
- if (nth)
- {
- cStep = currentStep / n;
- }
- else
- cStep = currentStep;
-
- if (con0) ** this value was saved in initsim message
- {
- plotNewPoint(0,0,cStep,con0in);
- con0Out = con0In; ** pass to output also
- }
- else ** get output from stored signal
- con0out = GetSignalValue(0, 0, currentTime);
-
- if (con1)
- {
- plotNewPoint(0,1,cStep,con1in);
- con1Out = con1In; ** pass to output also
- }
- else ** get output from stored signal
- con1Out = GetSignalValue(0, 1, currentTime);
-
- if (con2)
- {
- plotNewPoint(0,2,cStep,con2in);
- con2Out = con2In; ** pass to output also
- }
- else ** get output from stored signal
- con2Out = GetSignalValue(0, 2, currentTime);
-
- if (con3)
- {
- plotNewPoint(0,3,cStep,con3in);
- con3Out = con3In; ** pass to output also
- }
- else ** get output from stored signal
- con3Out = GetSignalValue(0, 3, currentTime);
-
- ** sysGlobal2 is the file reference number for the DEBUG TRACE
- if( sysGlobal2 != 0.0 ) ** 0 is error for open file for TRACE
- {
- // template for trace: |BLOCK NAME *****************|block number |BLOCK NUMBER*******|.| Current Time:|CURRENTTIME |.|
- fileWrite(sysGlobal2,"Plotter,I/O block number "+(myBlockNumber())+". Current Time:"+currentTime+".","",True);
- if(getBlockLabel(myBlockNumber()) != "")
- fileWrite(sysGlobal2,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
- fileWrite(sysGlobal2," Input 1 = "+con0In,"",True);
- fileWrite(sysGlobal2," Input 2 = "+con1In,"",True);
- fileWrite(sysGlobal2," Input 3 = "+con2In,"",True);
- fileWrite(sysGlobal2," Input 4 = "+con3In,"",True);
- fileWrite(sysGlobal2," ","",True);
- }
- }
-
-
- on endsim
- {
- integer loop, i;
- string str;
-
- if( showEnd )
- showPlot(0, "Plotter I/O");
-
- if (con0 || con1 || con2 || con3)
- pushPlotPic(0);
-
- ** sysGlobal1 is the file reference number for the TEXT REPORT
- if( sysGlobal1 != 0.0 ) ** 0 is error, check for open file for REPORT
- {
- // template for report: |BLOCK NAME *****************|block number |BLOCK NUMBER*******
- fileWrite(sysGlobal1,"Plotter, I/O block number "+(myBlockNumber()),"",True);
- if(getBlockLabel(myBlockNumber()) != "")
- fileWrite(sysGlobal1,"Block Label: "+getBlockLabel(myBlockNumber()),"",True);
- if( comments != "" )
- fileWrite(sysGlobal1," "+comments,"",True);
- fileWrite(sysGlobal1," Input Parameters:","",True);
- if( showDuring )
- fileWrite(sysGlobal1," Plot is shown during simulation","",True);
- else
- fileWrite(sysGlobal1," Plot is hidden during simulation","",True);
-
- i = 0;
- loop = TRUE;
- while(loop)
- {
- str = "";
- if (con0)
- str = p0[i];
- str += " ";
- if (con1)
- str += p1[i];
- str += " ";
- if (con2)
- str += p2[i];
- str += " ";
- if (con3)
- str += p3[i];
- fileWrite(sysGlobal1, str, "", true);
- i++;
- if (i >= numSteps-1)
- {
- loop = FALSE;
- break;
- }
- if ((!con0 || novalue(p0[i])) &&
- (!con1 || novalue(p1[i])) &&
- (!con2 || novalue(p2[i])) &&
- (!con3 || novalue(p3[i])))
- loop = FALSE;
- }
-
- fileWrite(sysGlobal1," ","",True);
- }
- }
-
-
- on dialogOpen
- {
- showplot(0, "Plotter Input/Output");
- abort; ** stop the dialog from opening!
- }
-
-
- on showP
- {
- showplot(0, "Plotter Input/Output");
- }
-
-
- on createBlock
- {
- ** install a dummy axis
- installAxis(0, "Plotter I/O", "Time", FALSE, 0.0, 1.0,
- "Value", 0, -1.0, 1.0, "Y2", 0, -1.0, 1.0,
- blackpattern, blackcolor, 100);
-
- ** now, install 4 dummy array signals
- ** to store plotting values from a simulation
- ** or from Pasteing (Importing) tabular data
-
- makeArray(p0, 0);
- installArray(0, 0, "", p0, 0.0, 1.0,
- 0, 0, blackPattern, cyanColor);
- makeArray(p1, 0);
- installArray(0, 1, "", p1, 0.0, 1.0,
- 0, 0, dkgrayPattern, redColor);
- makeArray(p2, 0);
- installArray(0, 2, "", p2,0.0, 1.0,
- 0, 0, grayPattern, greenColor);
- makeArray(p3, 0);
- installArray(0, 3, "", p3, 0.0, 1.0,
- 0, 0, ltgrayPattern, blackColor);
-
- showDuring = 1; ** default show plot during simulation
- nth = FALSE;
- n = 10;
- }
-
-
- on openModel
- {
- if(!showDuring && !showEnd && !noPlot)
- noPlot = 1;
- }